#if defined(MODBUS_TCP) || defined(MODBUS_RTU)
#if defined(PLC_IS_APP) || defined(PLC)

#include "plc_modbus.h"
#include "rte_abi.h"

void s1234_L(const char *s, char *d) {
    d[0] = s[0];
    d[1] = s[1];
    d[2] = s[2];
    d[3] = s[3];
    d[4] = s[4];
    d[5] = s[5];
    d[6] = s[6];
    d[7] = s[7];
}

void s1234_D(const char *s, char *d) {
    d[0] = s[0];
    d[1] = s[1];
    d[2] = s[2];
    d[3] = s[3];
}

void s1234_W(const char *s, char *d) {
    d[0] = s[0];
    d[1] = s[1];
}

void s1234_B(const char *s, char *d) {
    d[0] = s[0];
}

void s1234_X(const char *s, char *d) {
    d[0] = s[0];
}

void s4321_D(const char *s, char *d) {
    d[0] = s[3];
    d[1] = s[2];
    d[2] = s[1];
    d[3] = s[0];
}

void s4321_W(const char *s, char *d) {
    d[0] = s[1];
    d[1] = s[0];
}

void s4321_B(const char *s, char *d) {
    d[0] = s[1];
}

void s4321_X(const char *s, char *d) {
    d[0] = s[1];
}

void s2143_D(const char *s, char *d) {
    d[0] = s[1];
    d[1] = s[0];
    d[2] = s[3];
    d[3] = s[2];
}

void s2143_W(const char *s, char *d) {
    d[0] = s[1];
    d[1] = s[0];
}

void s2143_B(const char *s, char *d) {
    d[0] = s[1];
}

void s2143_X(const char *s, char *d) {
    d[0] = s[1];
}

void s3412_D(const char *s, char *d) {
    d[0] = s[2];
    d[1] = s[3];
    d[2] = s[0];
    d[3] = s[1];
}

void s3412_W(const char *s, char *d) {
    d[0] = s[0];
    d[1] = s[1];
}

void s3412_X(const char *s, char *d) {
    d[0] = s[0];
}

void s3412_B(const char *s, char *d) {
    d[0] = s[0];
}

int mb_master_connect_rte(client_node_t *t) {
    t->nd = plc_rte->mb_master_abi->mb_master_connect(t);
    return 0;
}

int mb_master_close_rte(client_node_t *t) {
    return plc_rte->mb_master_abi->mb_master_close(t);
}

int mb_slave_and_master_init_rte(int nd_count_tcp, int nd_count_rtu, int nd_count_ascii) {
    return plc_rte->mb_abi->mb_slave_and_master_init(nd_count_tcp, nd_count_rtu, nd_count_ascii);
}

int mb_slave_and_master_done_rte() { return plc_rte->mb_abi->mb_slave_and_master_done(); }

int mb_request_init_rte(client_request_t *t) { return plc_rte->mb_request_abi->mb_request_init(t); }

int mb_request_lock_rte(client_request_t *t) { return plc_rte->mb_request_abi->mb_request_lock(t); }

int mb_request_trylock_rte(client_request_t *t) { return plc_rte->mb_request_abi->mb_request_trylock(t); }

int mb_request_unlock_rte(client_request_t *t) { return plc_rte->mb_request_abi->mb_request_unlock(t); }

int mb_request_close_rte(client_request_t *t) { return plc_rte->mb_request_abi->mb_request_close(t); }

int mb_slave_init_rte(server_node_t *t) { return plc_rte->mb_slave_abi->mb_slave_init(t); }

/* Shut down the Modbus Library */
//int mb_slave_done() { return plc_rte->mb_slave_abi->mb_slave_done(); }

int mb_slave_close_rte(server_node_t *t) { return plc_rte->mb_slave_abi->mb_slave_close(t); }

#endif
#endif
